﻿namespace ExcelTool {
    using System.Reflection;

    static class START_PARAM {
        public static readonly string JSON_COMPACT = "-json_compact";
    }
    static class FILE_PATH {
        public static readonly string XML_CONFIG_DIR = "config";
        public static readonly string XML_COMMON_DEFINE = "common_define.xml";

        public static readonly string EXCEL_DATA_DIR = "source";

        public static readonly string CLIENT_JSON_WORKING_DIR = "output_json";
        public static readonly string SERVER_JSON_WORKING_DIR = "output_json_server";
        public static readonly string CS_WORKING_DIR = "output_cs";

        public static readonly string JSON_FILE_LIST_NAME = "metatable_list";
        public static readonly string CS_METATABLE_DEFINE = "tb_MetaTable_ID"; 
    }

    static class XML_ATTR_NAME {
        public const string NAME = "name";
        public const string VALUE = "value";
        public const string KEY = "key";
        public const string TYPE = "type";
        public const string TYPE_PARAM = "type_param";
        public const string DESC = "desc";
        public const string COUNT = "count";
        public const string PRIMARY = "primary";
        public const string TBNAME = "tablename";
        public const string VALID = "valid";
        public const string MODE = "mode";
    }

    static class XML_ELEMENTS_NAME {
        //解析XML时统一使用本组常量解析
        public const string CONST = "const";
        public const string ENUM = "enum";
        public const string CLASS = "class";
        public const string SUBCLASS = "subclass";
        public const string GROUP = "group";
        public const string DATASOURCE = "data_source";
        public const string ENTRY = "entry";

        public const string VALID = "validations";
        public const string REF = "ref";
    }

    static class FILE_EXT {
        public static readonly string JSON = ".json";
        public static readonly string CSHAPR = ".cs";
    }

    static class FILE_FORMAT {
        public static readonly string INDENT = "    ";

        public static readonly string PRIMARY_NAME = "meta_id";
        public static readonly string JSON_DATA_KEY = "data";

        public static readonly string SERIALIZABLE = "[Serializable]";
    }

    static class EXCEL_FILE_RULE {
        public static readonly string GROUP_ID = "id";  //子Sheet中用于分组的表头名
        public static readonly int MAIN_DATA_SHEET_INDEX = 0; //每个Excel的第一张Sheet默认为主Sheet
        public static readonly int SUBSHEET_ID_COL_INDEX = 0; //子Sheet中ID列默认为第一列
        public static readonly int TABLEHEAD_LINE_COUNT = 1; //表头所占行数

    }

    static class XML_DATA_TYPE_NAME {
        //转换Excel数据时才使用本组定义的类型概念
        public static readonly string INT        = "int";
        public static readonly string STR        = "string";
        public static readonly string ENUM       = "enum";
        public static readonly string SUBCLASS   = "subclass";
        public static readonly string GROUP      = "group";
        public static readonly string CLASS      = "class";
        public static readonly string DOUBLE     = "double";

        public static bool CheckTypeValid(string type) {
            FieldInfo[] fields = typeof(XML_DATA_TYPE_NAME).GetFields();
            foreach(FieldInfo item in fields) {
                string name = (string)item.GetValue(null);
                if(string.Compare(name, type) == 0) {
                    return true;
                }
            }

            return false;
        }
        //检查是否是基础类型
        public static bool IsBaseType(string type) {
            if(type == INT || type == STR || type == DOUBLE) {
                return true;
            }
            return false;
        }
        public static bool IsReferenceType(string type) {
            if(type == SUBCLASS || type == GROUP) {
                return true;
            }
            return false;
        }
        //检测主键的配置类型，只有int和string可以作为主键
        public static bool PrimaryKeyType(string type) {
            if(type == INT || type == STR || type == ENUM) {
                return true;
            }

            return false;
        }
    }

    public enum JSON_MODE {
        CLIENT = 1,
        SERVER = 1 << 1,
        COMMON = CLIENT | SERVER, 
    }

}
